home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / rcs55.zip / IDENT.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  5KB  |  192 lines

  1. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  2.    Copyright 1990 by Paul Eggert
  3.    Distributed under license by the Free Software Foundation, Inc.
  4.  
  5. This file is part of RCS.
  6.  
  7. RCS is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. RCS is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with RCS; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21. Report problems and direct all questions to:
  22.  
  23.     rcs-bugs@cs.purdue.edu
  24.  
  25. */
  26.  
  27. /*
  28.  *                     RCS identification operation
  29.  */
  30.  
  31. /* $Log: ident.c%v $
  32.  * Revision 1.2  1991/08/23  13:29:39  SGP
  33.  * Ported to MSDOS using Borland C++
  34.  *
  35.  * Revision 5.0  1990/08/22  08:12:37  eggert
  36.  * Don't limit output to known keywords.
  37.  * Remove arbitrary limits and lint.  Ansify and Posixate.
  38.  *
  39.  * Revision 4.5  89/05/01  15:11:54  narten
  40.  * changed copyright header to reflect current distribution rules
  41.  * 
  42.  * Revision 4.4  87/10/23  17:09:57  narten
  43.  * added exit(0) so exit return code would be non random
  44.  * 
  45.  * Revision 4.3  87/10/18  10:23:55  narten
  46.  * Updating version numbers. Changes relative to 1.1 are actually relative
  47.  * to 4.1
  48.  * 
  49.  * Revision 1.3  87/07/09  09:20:52  trinkle
  50.  * Added check to make sure there is at least one arg before comparing argv[1]
  51.  * with "-q".  This necessary on machines that don't allow dereferncing null
  52.  * pointers (i.e. Suns).
  53.  * 
  54.  * Revision 1.2  87/03/27  14:21:47  jenkins
  55.  * Port to suns
  56.  * 
  57.  * Revision 4.1  83/05/10  16:31:02  wft
  58.  * Added option -q and input from reading stdin.
  59.  * Marker matching is now done with trymatch() (independent of keywords).
  60.  * 
  61.  * Revision 3.4  83/02/18  17:37:49  wft
  62.  * removed printing of new line after last file.
  63.  *
  64.  * Revision 3.3  82/12/04  12:48:55  wft
  65.  * Added LOCKER.
  66.  *
  67.  * Revision 3.2  82/11/28  18:24:17  wft
  68.  * removed Suffix; added ungetc to avoid skipping over trailing KDELIM.
  69.  *
  70.  * Revision 3.1  82/10/13  15:58:51  wft
  71.  * fixed type of variables receiving from getc() (char-->int).
  72. */
  73.  
  74. #include  "rcsbase.h"
  75.  
  76. static int match P((FILE*));
  77. static int scanfile P((FILE*));
  78.  
  79. mainProg(identId, "ident", "$Id: ident.c%v 1.2 1991/08/23 13:29:39 SGP Exp $")
  80. /*  Ident searches the named files for all occurrences
  81.  *  of the pattern $keyword:...$, where the keywords are
  82.  *  Author, Date, Header, Id, Log, RCSfile, Revision, Source, and State.
  83.  */
  84.  
  85. {
  86.    FILE *fp;
  87.    int quiet;
  88.    int status = EXIT_SUCCESS;
  89.  
  90.    if ((quiet  =  argc > 1 && strcmp("-q",argv[1])==0)) {
  91.         argc--; argv++;
  92.    }
  93.  
  94.    if (argc<2) {
  95.      if ((scanfile(stdin) == 0) && !quiet)
  96.         VOID fprintf(stderr, "%s warning: no id keywords in input\n", cmdid);
  97.     exitmain(EXIT_FAILURE);
  98.    }
  99.  
  100.    while ( --argc > 0 ) {
  101.       if ( (fp = fopen(*++argv, "rb") ) == NULL ) {
  102.      VOID fprintf(stderr,  "%s error: can't open %s\n", cmdid, *argv);
  103.      status = EXIT_FAILURE;
  104.          continue;
  105.       } else {
  106.          VOID printf( "%s:\n", *argv);   /*  print file name  */
  107.      if ((scanfile(fp) == 0) && !quiet)
  108.         VOID fprintf(stderr, "%s warning: no id keywords in %s\n", cmdid, *argv);
  109.      if (argc>1) VOID putchar('\n');
  110.      VOID fclose(fp);
  111.       }
  112.    }
  113.    exitmain(status);
  114. }
  115.  
  116. #if lint
  117. #    define exiterr identExit
  118. #endif
  119.     exiting void
  120. exiterr()
  121. {
  122.     _exit(EXIT_FAILURE);
  123. }
  124.  
  125.  
  126.     static int
  127. scanfile(register FILE *file)
  128. /* Function: scan an open file with descriptor file for keywords.
  129.  * Returns nonzero if a match is found.
  130.  */
  131. {
  132.    register int matched;
  133.    register int c;
  134.  
  135.  
  136.    matched = false;
  137.    c = 0;
  138.    while (c != EOF) {
  139.       if (c == KDELIM) {
  140.      if ((c = match(file)))
  141.         continue;
  142.      matched = true;
  143.       }
  144.       c = getc(file);
  145.    }
  146.    return matched;
  147. }
  148.  
  149.  
  150.  
  151.     static int
  152. match(register FILE *fp)
  153.  /* group substring between two KDELIM's; then do pattern match */
  154. {
  155.    char line[BUFSIZ];
  156.    register int c;
  157.    register char * tp;
  158.  
  159.    tp = line;
  160.    while ((c = getc(fp)) != VDELIM)
  161.       switch (ctab[c]) {
  162.      case LETTER: case Letter:
  163.         *tp++ = c;
  164.         if (tp < line+sizeof(line)-4)
  165.            break;
  166.         /* fall into */
  167.      default:
  168.         return c ? c : '\n'/* anything but 0 or KDELIM or EOF */;
  169.       }
  170.    *tp++ = c;
  171.    if ((c = getc(fp)) != ' ')
  172.       return c ? c : '\n';
  173.    *tp++ = c;
  174.    while( (c = getc(fp)) != KDELIM ) {
  175.       switch (ctab[c]) {
  176.      default:
  177.         *tp++ = c;
  178.         if (tp < line+sizeof(line)-2)
  179.            break;
  180.         /* fall into */
  181.      case EOFILE: case NEWLN: case UNKN:
  182.         return c ? c : '\n';
  183.       }
  184.    }
  185.    if (tp[-1] != ' ')
  186.       return tp[-1];
  187.    *tp++ = c;     /*append trailing KDELIM*/
  188.    *tp   = '\0';
  189.    VOID fprintf(stdout, "     %c%s\n", KDELIM, line);
  190.    return 0;
  191. }
  192.